home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************************
- * *
- * PROGRAM: SetDTool *
- * VERSION: 1.3 *
- * SOURCE CODE: 14 *
- * DATE: 13.8.2000 *
- * LANGUAGE: Assembler (DevPac V3.14) *
- * SYSTEM: A1200 KS 40.68 WB 40.42 2MB chip 64MB fast 68030/50mhz *
- * *
- * AUTHOR: Joerg Riemer 14167 Berlin/SchottmuellerStr.107/Germany *
- * EMAIL: joerg_riemer@freenet.de / mission@cs.tu-berlin.de *
- * *
- * COMMENT: cli-command to change the defaulttool entry *
- * defined in project-icons. *
- * *
- * TEMPLATE: FILE,TOOL/K,LIST/S,ALL/S,QUIET/S *
- * *
- * OPTION: To get a shorter file, set BSS_Section to NULL and use *
- * StripHunk instead to generate a Code_BSS-segment. it *
- * spares some bytes! but for anybody don't know what *
- * this means: "leave it as it is" *
- * *
- * StripHunk is available at AmiNet dev/misc/... *
- * *
- * for suggestions, hints/tips, and/or questions *
- * send an email (see above for address) *
- * *
- *****************************************************************************
-
- * opt d+
-
- BSS_Section set 1
-
- *****************************************************************************
-
- output ram:SetDTool
-
- ************************************************ exec definitions ***********
-
- _LVOOpenLibrary equ -552
- _LVOCloseLibrary equ -414
-
- ************************************************ dos definitions ************
-
- _LVOOutput equ -060
- _LVOIoErr equ -132
- _LVOFPutC equ -312
- _LVOFPuts equ -342
- _LVOSetIoErr equ -462
- _LVOPrintFault equ -474
- _LVOReadArgs equ -798
- _LVOFreeArgs equ -858
- _LVOMatchFirst equ -822
- _LVOMatchNext equ -828
- _LVOMatchEnd equ -834
-
- ap_BreakBits equ $008
- ap_Flags equ $010
- ap_Strlen equ $012
- ap_Info equ $014
-
- fib_DirEntryType equ $004
-
- APB_DOWILD equ $000
- APB_DODIR equ $002
- APB_DIDDIR equ $003
-
- SIGBREAKB_CTRL_C equ $00C
- SIGBREAKB_CTRL_D equ $00D
- SIGBREAKB_CTRL_E equ $00E
- SIGBREAKB_CTRL_F equ $00F
-
- ************************************************ icon definitions ***********
-
- _LVOGetDiskObject equ -078
- _LVOPutDiskObject equ -084
- _LVOFreeDiskObject equ -090
-
- WBPROJECT equ $004
- do_Type equ $030
- do_DefaultTool equ $032
-
- ************************************************ bss datas ******************
-
- Anchorpath rs.b 280 ;size_of anchorpath
- PNameOrg rs.b 256 ;size_of ap_strlen (pathname)
- PNameBuf rs.b 256 ;size_of workbuffer
- DOSBase rs.l 1 ;ptr. base of library
- ICOBase rs.l 1 ;ptr. base of library
-
- Filename rs.l 1 ;argarray ptr. filename
- Tool rs.l 1 ;argarray ptr. newtoolstring
- List rs.l 1 ;argarray flag (list only)
- All rs.l 1 ;argarray flag (do subdirs)
- Quiet rs.b 1 ;argarray flag (no output)
- EntryType rs.b 1 ;flag (found #?.info)
- Flag3 rs.b 1 ;pad
- Flag4 rs.b 1 ;pad
-
- RDArgs rs.l 1 ;ptr. rdargs structure
- RCode1 rs.l 1 ;errorcode > rc
- RCode2 rs.l 1 ;errorcode > result2
- MatchReturn rs.l 1 ;errorcode (matchnext)
- DObject rs.l 1 ;ptr. workbench diskobject
- DefTool rs.l 1 ;ptr. do_defaulttool
- FCount rs.l 1 ;counter (files proccessed)
- StrEnd rs.l 1 ;ptr. stringend w/o ".info"
-
- BSS_Size rs.b 0 ;bss_size over all
-
- *****************************************************************************
-
- Start movem.l D1-D7/A0-A6,-(SP) ;save registers
-
- if BSS_Section ;check assembler condition
-
- movea.l Start-4(pc),A5 ;get bss_section
- addq.l #1,A5 ;skip pointer (next segment)
- adda.l A5,A5 ;convert bpcl_pointer
- adda.l A5,A5 ;to real_address
-
- elseif ;otherwise
-
- lea DataBase(pc),A5 ;set working area
-
- endc ;end condition
-
- ************************************************ open libraries *************
-
- moveq #20,D0 ;failat level
- move.l D0,RCode1(A5) ;preset error (no library)
-
- movea.l 4.w,A6 ;set EXEC to call a function
-
- moveq #37,D0 ;required library version
- lea DOSName(pc),A1 ;set library name
- jsr _LVOOpenLibrary(A6) ;use EXEC to (openlibrary)
- move.l D0,DOSBase(A5) ;save base
-
- beq.b CloseLibs ;branch if not open
-
- moveq #37,D0 ;required library version
- lea ICOName(pc),A1 ;set library name
- jsr _LVOOpenLibrary(A6) ;use EXEC to (openlibrary)
- move.l D0,ICOBase(A5) ;save base
-
- beq.b CloseLibs ;branch if not open
-
- *****************************************************************************
-
- bsr.b Main
-
- ************************************************ close libraries ************
-
- CloseLibs movea.l 4.w,A6 ;set EXEC to call a function
-
- move.l ICOBase(A5),D1 ;get base_ptr
- beq.b CloseDOS ;branch when not open
- movea.l D1,A1 ;set base_ptr
- jsr _LVOCloseLibrary(A6) ;use EXEC to (closelibrary)
-
- CloseDOS move.l DOSBase(A5),D1 ;get base_ptr
- beq.b ExitDOS ;branch when not open
- movea.l D1,A1 ;set base_ptr
- jsr _LVOCloseLibrary(A6) ;use EXEC to (closelibrary)
-
- ExitDOS move.l RCode1(A5),D0 ;set returncode
- movem.l (SP)+,D1-D7/A0-A6 ;restore registers
- rts ;go back (shell)
-
- *****************************************************************************
-
- DOSName dc.b "dos.library",0
- ICOName dc.b "icon.library",0
-
- *****************************************************************************
-
- version dc.b "$VER: SetDTool 1.3 14 (13.8.00) by joerg riemer mar'00",0
-
- *****************************************************************************
-
- cnop 0,4
-
- *****************************************************************************
-
- Main clr.l RCode1(A5) ;clear returncode
-
- bsr ReadArgs ;read user_arguments
- bsr CheckArgs ;check for legal arguments
-
- bsr InitAPath ;prepare anchorpath
- bsr MatchFirst ;search for filename
-
- Loop bsr CheckEntryType ;check for dir/file
- bsr MatchNext ;do matchnext first!!
- bsr.b SetDTool ;then edit prematched file
-
- Next move.l MatchReturn(A5),D1 ;check returncode (matchnext)
- beq.b Loop ;loop again when ok
-
- cmp.w #232,D1 ;check for 'no more entries'
- bne Error4 ;branch if not
-
- move.l #205,D1 ;preset "file not found"
- tst.l FCount(A5) ;found some files?
- beq Error4 ;branch if not
-
- move.l RCode2(A5),D1 ;check returncode2
- beq.b Quit0 ;branch if not set
-
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOSetIoErr(A6) ;use dos to set pr_result2
-
- Quit0 bsr MatchEnd ;free memory (anchorpath)
- Quit1 bsr FreeArgs ;free memory (readargs)
- rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ set default tool ***********
-
- SetDTool tst.b EntryType(A5) ;found a info_file?
- beq .Ready ;branch if not
-
- *********************** read [#?.info] file ****
-
- move.l StrEnd(A5),A2 ;remove suffix [.info]
- clr.b (A2) ;remove suffix [.info]
-
- lea PNameBuf(A5),A0 ;set filename
- move.l ICOBase(A5),A6 ;set library_base
- jsr _LVOGetDiskObject(A6) ;use icon to getdiskobject
- move.l D0,DObject(A5) ;got it?
- beq Error2 ;branch if not
-
- *********************** check for project.info *
-
- move.l D0,A0 ;set diskobject
- cmp.b #WBPROJECT,do_Type(A0) ;check for project_icon
- bne.b .FreeDObject ;branch if not
-
- *********************** set new defaulttool ****
-
- addq.l #1,FCount(A5) ;inc. files proccessed
-
- tst.b List(A5) ;list file only ?
- bne.b .PrintFName ;branch if so
-
- move.l do_DefaultTool(A0),DefTool(A5) ;save old defauft
- move.l Tool(A5),do_DefaultTool(A0) ;set new default
-
- movea.l A0,A1 ;set diskobject
- lea PNameBuf(A5),A0 ;set name used to put
- jsr _LVOPutDiskObject(A6) ;use icon to putdiskobject
- tst.l D0 ;save file failed?
- beq Error3 ;branch if so
-
- move.l DObject(A5),A0 ;get diskobject
- move.l DefTool(A5),do_DefaultTool(A0) ;restore deftool
-
- *********************** print path/filename ****
-
- .PrintFName tst.b Quiet(A5) ;do some output?
- bne.b .FreeDObject ;branch if not
-
- move.l StrEnd(A5),A2 ;restore filename
- move.b #".",(A2) ;restore filename
-
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOOutput(A6) ;search output_handle
-
- move.l D0,D1 ;set output
- lea PNameBuf(A5),A2 ;get filename to print
- move.l A2,D2 ;prepare dos_fputs
- jsr _LVOFPuts(A6) ;use dos to fputs
-
- tst.b List(A5) ;list file only ?
- bne.b .PrintNLine ;branch if so
-
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOOutput(A6) ;search output_handle
- move.l D0,D1 ;set output
- lea Text(pc),A2 ;get filename to print
- move.l A2,D2 ;prepare dos_fputs
- jsr _LVOFPuts(A6) ;use dos to fputs
-
- .PrintNLine movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOOutput(A6) ;search output_handle
- move.l D0,D1 ;set output
- moveq #$A,D2 ;set char. to print
- jsr _LVOFPutC(A6) ;use dos to fputc
-
- *********************** free icon memory *******
-
- .FreeDObject move.l DObject(A5),A0 ;get diskobject
- movea.l ICOBase(A5),A6 ;set icon_base
- jsr _LVOFreeDiskObject(A6) ;use icon to freediskobject
- .Ready rts
-
- *****************************************************************************
-
- Text dc.b " patched!",0
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ prepare anchorpath *********
-
- InitAPath moveq #00,D0 ;prepare register
- bset #SIGBREAKB_CTRL_C,D0 ;do break on <CTRL><C> !!!
- move.l D0,ap_BreakBits(A5) ;set bit
- * bset #APB_DOWILD,ap_Flags(A5)
- move.w #256,ap_Strlen(A5) ;set length of string_buffer
- rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ matchfirst pattern *********
-
- MatchFirst move.l Filename(A5),D1 ;get user pattern/file
- bne.b .GetPattern
-
- lea Pattern(pc),A2 ;force filename
- move.l A2,D1 ;and set
-
- .GetPattern lea Anchorpath(A5),A2 ;get anchorpath
- move.l A2,D2 ;used for matching
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOMatchFirst(A6) ;use dos to matchfirst
- move.l D0,MatchReturn(A5) ;save returncode
- beq.b .Ready ;branch if ok
-
- addq #4,SP ;clear return_address
- pea Next(pc) ;set new one
-
- .Ready rts ;go back
-
- *****************************************************************************
-
- Pattern dc.b "#?",0,0 ;filename
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ matchnext pattern **********
-
- MatchNext tst.l All(A5) ;scan subdirectories ?
- beq.b .MatchNext ;branch if not
-
- lea ap_Info(A5),A0 ;get fileinfoblock
- tst.l fib_DirEntryType(A0) ;type = file ?
- bmi.b .MatchNext ;branch if so
-
- bclr #APB_DIDDIR,ap_Flags(A5)
- bne.b .MatchNext
- bset #APB_DODIR,ap_Flags(A5)
-
- .MatchNext lea Anchorpath(A5),A1 ;get anchorpath structure
- move.l A1,D1 ;prepare matchnext
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOMatchNext(A6) ;use dos to matchnext
- move.l D0,MatchReturn(A5) ;save return_code
- rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ free memory matchfirst/next
-
- MatchEnd lea Anchorpath(A5),A1 ;get anchorpath structure
- move.l A1,D1 ;prepare matchend
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOMatchEnd(A6) ;use dos to matchend
- rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ test for #?.info file ******
-
- CheckEntryType lea ap_Info(A5),A0 ;get fileinfoblock
- tst.l fib_DirEntryType(A0) ;type = file ?
- bpl.b .Ready ;branch, type is directory
-
- lea PNameOrg(A5),A0 ;get filename
- lea PNameBuf(A5),A1 ;set buffer
- .CopyString move.b (A0)+,(A1)+ ;copy string
- bne.b .CopyString ;until end
-
- subq #6,A1 ;search for suffix '.info'
- cmp.b #".",(A1) ;first test
- bne.b .Ready ;branch if fail
-
- move.l A1,StrEnd(A5) ;set string_end w/o suffix
- addq #1,A1 ;skip '.'
- move.b (A1)+,D0 ;second test, get char
- bset #5,D0 ;set lowercase
- rol.l #8,D0 ;make room for next char
- move.b (A1)+,D0 ;get char
- bset #5,D0 ;set lowercase
- rol.l #8,D0 ;make room for next char
- move.b (A1)+,D0 ;get char
- bset #5,D0 ;set lowercase
- rol.l #8,D0 ;make room for next char
- move.b (A1)+,D0 ;get char
- bset #5,D0 ;set lowercase
- cmp.l #"info",D0 ;suffix = '.info' ?
-
- .Ready seq EntryType(A5) ;set if so
- rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ read arguments *************
-
- ReadArgs lea Template(pc),A1 ;get template
- lea Filename(A5),A2 ;get arg_array
- move.l A1,D1 ;set arg_template
- move.l A2,D2 ;set array
- moveq #0,D3 ;set args (unused)
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOReadArgs(A6) ;use dos to readargs
- move.l D0,RDArgs(A5) ;save returncode
- beq Error1 ;branch on wrong args
- rts ;else, go back
-
- *****************************************************************************
-
- cnop 0,4
-
- *****************************************************************************
-
- CheckArgs moveq. #116,D1 ;errorcode "wrong args..."
- move.l Filename(A5),D0 ;either the filename
- or.l All(A5),D0 ;or the flag are required
- beq.b Error5 ;branch if nothing set
-
- moveq #118,D1 ;errorcode "to much args..."
- and.l List(A5),D0 ;check list flag
- bne.b .CheckTool ;branch if set
-
- or.l Tool(A5),D0 ;check for tool
- beq.b Error5 ;branch if not set
- rts ;go back
-
- cnop 0,4
-
- .CheckTool and.l Tool(A5),D0 ;no tool required when list
- bne.b Error5 ;branch when both set
- or.l Quiet(A5),D0 ;list and quiet is useless
- bne.b Error5 ;branch if so
- rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- ************************************************ free argument buffer *******
-
- FreeArgs move.l RDArgs(A5),D1 ;get arg_structure
- beq.b .Ready ;branch if not set
- move.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOFreeArgs(A6) ;use dos to freeargs
- .Ready rts ;go back
-
- *****************************************************************************
-
- cnop 0,4
-
- *****************************************************************************
-
- Error5 addq #4,SP ;clear return_address
-
- Error4 move.l D1,RCode2(A5) ;set errorcode
- pea Quit1(pc) ;set return_address
- bra.b Error ;print error
-
- *****************************************************************************
-
- cnop 0,4
-
- *****************************************************************************
-
- Error3 move.l DObject(A5),A0 ;get diskobject
- move.l DefTool(A5),do_DefaultTool(A0) ;restore deftool
-
- movea.l ICOBase(A5),A6 ;set icon_base
- jsr _LVOFreeDiskObject(A6) ;use icon to freediskobject
-
- *****************************************************************************
-
- Error2 move.l StrEnd(A5),A2 ;restore filename
- move.b #".",(A2) ;restore filename
-
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOOutput(A6) ;search output_handle
-
- move.l D0,D1 ;set output
- lea PNameBuf(A5),A2 ;get filename to print
- move.l A2,D2 ;prepare dos_fputs
- jsr _LVOFPuts(A6) ;use dos to fputs
-
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOOutput(A6) ;search output_handle
- move.l D0,D1 ;set output
- moveq #$A,D2 ;set char. to print
- jsr _LVOFPutC(A6) ;use dos to fputc
-
- addq #4,SP ;clear return_address
- pea Next(pc) ;set new one
- bra.b Error0 ;print error
-
- *****************************************************************************
-
- cnop 0,4
-
- *****************************************************************************
-
- Error1 addq #4,SP ;clear return_address
-
- *****************************************************************************
-
- Error0 movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOIoErr(A6) ;use dos to get ioerr
- move.l D0,RCode2(A5) ;save as pr_result2
- bne.b Error ;got one???
-
- move.l #209,RCode2(A5) ;hmm???...what's wrong???
-
- *****************************************************************************
-
- Error move.l RCode2(A5),D1 ;get errorcode
- movea.l DOSBase(A5),A6 ;set dos_base
- jsr _LVOSetIoErr(A6) ;use dos to set pr_result2
-
- move.l RCode2(A5),D1 ;get errorcode
- moveq #0,D2 ;prepare dos printfault
-
- cmp.w #304,D1 ;check for break by user
- beq.b .PrintFault ;branch if so
-
- lea Header(pc),A2 ;get head_text 'ERROR:'
- move.l A2,D2 ;set header
-
- .PrintFault jsr _LVOPrintFault(A6) ;use dos to printfault
-
- moveq #5,D0 ;set returncode rc=warn
- move.l D0,RCode1(A5) ;save
- rts ;go back
-
- *****************************************************************************
-
- Template dc.b "FILE,TOOL/K,LIST/S,ALL/S,QUIET/S",0
- Header dc.b "ERROR",0
-
- *****************************************************************************
-
- if BSS_Section
-
- SECTION SetDTool_bss,BSS
-
- elseif
-
- cnop 0,4
-
- endc
-
- *****************************************************************************
-
- DataBase ds.b BSS_Size
-
- end of source **************************************************************
-